﻿<%@ include file="../include/top.jsp" %>
<%@ include file="../include/errorArea.jsp" %>

<link rel="stylesheet" href="${baseURL}/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script language="javascript" type="text/javascript" src="${baseURL}/js/jquery.ztree.all-3.5.min.js">
</script>
<SCRIPT type="text/javascript">
	var setting = {
		view: {
			dblClickExpand: false
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			onClick: onClick
		}
	};

	var zNodes = ${treedata}; //后台返回的数据

	function onClick(e,treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		zTree.expandNode(treeNode);

		//叶节点，并且不是第一层节点(第一层节点的pId是null)
		if(!treeNode.isParent && treeNode.pId!=null){
			nodes = zTree.getSelectedNodes();
			$("#selectedNodeName").attr("value", treeNode.name);
			$("#nodeId").attr("value", treeNode.id);
		}
	}

	function showMenu() {
		var cityObj = $("#selectedNodeName");
		var cityOffset = $("#selectedNodeName").offset();
		$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");

		$("body").bind("mousedown", onBodyDown);
	}
	function hideMenu() {
		$("#menuContent").fadeOut("fast");
		$("body").unbind("mousedown", onBodyDown);
	}
	function onBodyDown(event) {
		if (!(event.target.id == "menuBtn" || event.target.id == "selectedNodeName" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
			hideMenu();
		}
	}

	$(document).ready(function(){
		var flag=${add};
		if(flag==true)
			alert("已添加到购物车");
		$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		
		var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
		var nodes = treeObj.getNodesByParam("id", "${formdata.nodeId}", null);
		if (nodes.length>0) {
			treeObj.selectNode(nodes[0]);
		}

	});
</SCRIPT>

<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" style="margin-top:10px;">
            <tr>
              <td colspan="2" align="left" valign="middle" class="text_gray2">
              
              <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#96bee2">
                  <tr>
                    <td height="21" background="${baseURL}/images/table_bg.jpg">&nbsp;&nbsp;<span class="text_blue_b">
             
	  <c:if test="${not empty formdata.id && formdata.id>0}">
<img src="${baseURL}/images/bit_edit.png" width="16" height="14" border="0" align="absmiddle" /> 编辑商品</c:if></span></td>
                  </tr>
                  <tr>
                    <td height="13" align="center" valign="top" bgcolor="#FFFFFF">
					<form name="myForm" method="POST" action="${baseURL}/companyAdmin/addToShop" onsubmit="return countPrice()">
					<input type="hidden" name="id" value="${formdata.id}" />
				
<table width="100%" border="0" align="center" id="listTable" bgcolor="#FFFFFF" cellpadding="1" cellspacing="0">
	<tr style="display:none">
	  <td colspan="2" height="0" >
	  </td>
    </tr>
    <tr>
		<td align="right">商品ID：</td>
		<td align="left">${formdata.id}</td>
	</tr>
    <tr>
		<td align="right">商品编码：</td>
		<td align="left">${formdata.productCode}</td>
	</tr>
	<tr>
		<td align="right"><span class="mustInput">*</span>商品名称 ：</td>
		<td align="left">${formdata.productName}</td>
    </tr>
	<tr>
	  <td align="right" width="120"><span class="mustInput">*</span>商品所属分类：</td>
      <td align="left" colspan="3">${formdata.selectedNodeName}</td>
    </tr>
    <tr>
		<td align="right">商品图片</td>
		<td><img src="http://localhost/${formdata.productPic1}" width="100" height="100"/></td>
			</td>
	</tr>
    <tr>
		<td align="right">供货商：</td>
		<td align="left">${formdata.supplierId}</td>
	</tr>
	<tr>
		<td align="right">库存数量：</td>
		<td align="left">${formdata.stockNumber}</td>
	</tr>
	<tr>
		<td align="right">销售数量：</td>
		<td align="left">${formdata.sellNumber}</td>
	</tr>
    <tr> 
      <td align="right">商品介绍： </td>
	  <td>
	  ${formdata.productContent}</td>
    </tr>
   
	
	<tr>
	  <td align="right">零售价格：</td>
      <td align="left">${formdata.sellPrice}元（人民币）
		</td>
	</tr>
	
	<tr>
	  <td colspan="2" align="center">
	  购买数量：
	   	<input name="count" id="count" type="text" value=""/>
	  	<input name="submit" type="submit" value="加入购物车" class="myButton"/>
	    &nbsp;&nbsp;
        <input name="button" type="button"
			onclick="history.go(-1)" value="返回" class="myButton"/></td>
    </tr>
	<tr>
	  <td colspan="4" align="center">&nbsp;</td>
    </tr>
</table>
</form></td>
                  </tr>
              </table></td>
            </tr>
</table>

<script>
//计算价格，总是向上取整
function countPrice(){
	if(isNaN($('#count').val()))
		{
		alert("请输入数字");
		return false;
		}
	var count=parseInt($('#count').val());
	var sum=parseInt(${formdata.stockNumber});
	if(count>sum)
	{
		alert("库存不足");
		return false;
		}
}
</script>
<%@ include file="../include/bottom.jsp" %>